<?php

class ActionBase extends CAction {
	public $view;
	public $layout;	
	
	public $scripts = array();
	
	protected function registerAssets() {
		if(!$this->scripts) return;
		$cs = Yii::app()->clientScript;
		$am = Yii::app()->assetManager;
		foreach($this->scripts as $one) {
			if(is_string($one)) {
				if(strncasecmp($one, 'publish:', 8) === 0) {
					$path = Yii::getPathOfAlias(substr($one, 8)).'.js';
					$url = $am->publish($path, false, -1, true);
				} else {
					$url = $one;
				}
				$cs->registerScriptFile($url);
			} else {
				if(!$one[0]) $one[0] = mktime().mt_rand(1000, 9999); 
				call_user_func_array(array($cs, 'registerScript'), $one);
			}
		}
	}
	
	public function prepare() {
		$this->registerAssets();
		$this->controller->layout = $this->layout;
	}
	
}

?>